11110 - Equidivisions (DFS, maratón colombiana) &&
[and.git] / 10003 - Cutting sticks / robado.cpp
blobf670115f0e14ef0cdbc3a2f3c4a7bf6a209003e1
1 //http://acm.uva.es/board/viewtopic.php?t=1543&highlight=10003&sid=707852836d9f5e46db0ea0865323a05f
3 #include<stdio.h>
4 #include<values.h>
6 #define MAX 60
7 #define inf MAXLONG
9 int main()
11 long L,N,i,j,n,x,y,q,l,k,t,sum,m[MAX][MAX],p[MAX];
13 while(scanf("%ld",&L)==1 && L)
15 scanf("%ld",&N);
17 y = 0;
19 for(i=1;i<=N;i++)
21 scanf("%ld",&x);
22 p[i] = x - y;
23 y = x;
25 p[i] = L - y;
27 n = i;
29 for(i=0;i<=n;i++)
30 m[i][i] = 0;
32 for(l=2;l<=n;l++)
34 for(i=1;i<=n-l+1;i++)
36 j = i + l - 1;
37 m[i][j] = inf;
40 for(k=i;k<=j-1;k++)
42 q = m[i][k] + m[k+1][j] ;
44 sum = 0;
46 for(t=i;t<=j;t++)
47 sum += p[t];
49 q += sum;
51 if(q<m[i][j])
52 m[i][j] = q;
57 printf("The minimum cutting is %ld.\n",m[1][n]);
59 return 0;